﻿/*************************************************
作者: Plane
邮箱: 1785275942@qq.com
功能: UI管理服务

           ~~获取更多教学资讯~~
//----------------*----------------\\
        教学官网：www.qiqiker.com
        官方微信服务号: qiqikertuts
        Plane老师微信: PlaneZhong
\\----------------*----------------//
*************************************************/

using System.Collections.Generic;

public class UISvc : ILogic {
    //-------------Declaration----------------//
    PERoot root;
    LoadingWnd loadingWnd;
    TipsWnd tipsWnd;
    readonly Dictionary<UIWindow, WindowRoot> windowDic = new();

    //-------------Flow Functions-------------//
    public void Init() {
        root = PERoot.Instance;
        //top
        loadingWnd = root.transform.Find("Canvas/LoadingWnd").GetComponent<LoadingWnd>();
        windowDic.Add(UIWindow.Loading, loadingWnd);
        tipsWnd = root.transform.Find("Canvas/TipsWnd").GetComponent<TipsWnd>();
        windowDic.Add(UIWindow.Tips, tipsWnd);

        //base
        LoginWnd loginWnd = root.transform.Find("Canvas/LoginWnd").GetComponent<LoginWnd>();
        windowDic.Add(UIWindow.Login, loginWnd);
        CreateWnd createWnd = root.transform.Find("Canvas/CreateWnd").GetComponent<CreateWnd>();
        windowDic.Add(UIWindow.Create, createWnd);

        MajorWnd majorWnd = root.transform.Find("Canvas/MajorWnd").GetComponent<MajorWnd>();
        windowDic.Add(UIWindow.Major, majorWnd);
        SingleFBWnd singleFBWnd = root.transform.Find("Canvas/SingleFBWnd").GetComponent<SingleFBWnd>();
        windowDic.Add(UIWindow.SingleFuben, singleFBWnd);

        SetWindowState(UIWindow.Tips);
        this.Log("Init UISvc Done.");
    }
    public void Tick() { }
    public void UnInit() { this.Log("UnInit UISvc."); }
    
    //-------------Core Functions-------------//
    public void SetWindowState(UIWindow uiWindow, bool state = true) {
        if (windowDic.TryGetValue(uiWindow, out WindowRoot wnd)) {
            wnd.SetWindowState(state);
        }
    }
    public void SwitchStageBaseUI(CPlayMode modeEnum) {
        UIWindow uiWindow = UIWindow.None;
        switch (modeEnum) {
            case CPlayMode.Login:
                uiWindow = UIWindow.Login;
                break;
            case CPlayMode.Create:
                uiWindow = UIWindow.Create;
                break;
            case CPlayMode.Major:
                uiWindow = UIWindow.Major;
                break;
            case CPlayMode.Wild:
                uiWindow = UIWindow.Wild;
                break;
            case CPlayMode.Single:
                uiWindow = UIWindow.SingleFuben;
                break;
            case CPlayMode.Multiple:
                uiWindow = UIWindow.MultiFuben;
                break;
            //TODO
            case CPlayMode.Marriage:
            case CPlayMode.Fishing:
            case CPlayMode.Concert:
            case CPlayMode.None:
            default:
                break;
        }

        foreach (var item in windowDic) {
            WindowRoot window = item.Value;
            if (window.windowLayer == WindowLayer.BaseUI || window.windowLayer == WindowLayer.PopUI) {
                if (item.Key == uiWindow) {
                    window.SetWindowState();
                }
                else {
                    window.SetWindowState(false);
                }
            }
        }
    }
    
    //-------------Tool Functions-------------//
    public void ShowTips(string tips) {
        tipsWnd.AddTips(tips);
    }
    public void SetLoading(int pct, bool state = true) {
        loadingWnd.SetProgress(pct, state);
    }
}